﻿using AllInOne.Entity;
using AllInOne.EntityShowInfo;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;


namespace AllInOne.Common
{
    [ValueConversion(typeof(T_RegisterInfo), typeof(T_RegisterInfo))]
    public class ConverterProduct : IValueConverter
    {
        /// <summary>
        /// 由model -->view
        /// 说明：通过value及parameter就可以判断选中的是什么
        /// </summary>
        /// <param name="value">model上的原始值</param>
        /// <param name="targetType"></param>
        /// <param name="parameter">可以通过前端传进去的值</param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null || parameter==null)
            {
                return false;
            }
            ////如果值与参数据一致则返回选中
            //return value.ToString() == parameter.ToString();
            MessageAlert.Alert(parameter.ToString());
            //RegisterInfo_ExcelOut parameter=new RegisterInfo_ExcelOut(


            //bool boolValue = false;
            //if (value is string)
            //{
            //    if ((string)value == "启用")
            //    {
            //        boolValue = true;
            //    }
            //    if ((string)value == "关闭"|| (string)value == "")
            //    {
            //        boolValue = false;
            //    }
            //}
            //return boolValue;
            return null;
        }
        /// <summary>
        /// view ->model的转换
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((bool)value == true)
            {
                return "启用";
            }
            else
            {
                return "禁用";
            }
        }
    }

    public class MultiBinding2Converter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            //var selectItem = values[0] as ComboBoxItem;
            //var isChecked = values[1] as bool?;
            ////此处不需要该参数，这里只是展示Converter传参一个固定字符串
            //var para = parameter as string;
            //if (selectItem != null && selectItem.Tag.ToString() == "1" &&
            //    isChecked.HasValue && isChecked.Value)
            //    return Visibility.Visible;
            //return Visibility.Collapsed;

            try
            {
                if ((string)values[0] == "多种货物" && (string)values[1] != null)
                {
                    return values[1];
                }
            }
            catch (Exception)
            {
            }
            return values[0];
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }

}
